import { contextBridge, ipcRenderer } from 'electron';

export interface ElectronAPI {
  searchSoftware: (keyword: string) => Promise<SoftwareResult[]>;
  getSearchHistory: () => Promise<string[]>;
}

export interface SoftwareResult {
  name: string;
  description: string;
  website: string;
  icon: string;
  tags: string[];
}

const electronAPI: ElectronAPI = {
  searchSoftware: (keyword: string) => ipcRenderer.invoke('search-software', keyword),
  getSearchHistory: () => ipcRenderer.invoke('get-search-history'),
};

contextBridge.exposeInMainWorld('electronAPI', electronAPI);

declare global {
  interface Window {
    electronAPI: ElectronAPI;
  }
}
